var t, e = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), o = require("../../../mybehaviors/location/location");

Page((t = {
    behaviors: [ o ],
    data: {
        classifyShow: !1,
        hoursShow: !1,
        addressShow: !1,
        applyShow: !1,
        applyText: "",
        applyDescName: "",
        applyTextStatus: 0,
        strShow: !1,
        classifyIndex: 0,
        secondIndex: null,
        threeIndex: null,
        uploadUrl: "upload.uploadPic",
        anotherImgList: [],
        form: {
            store_name: "",
            first_category_id: 0,
            second_category_id: 0,
            third_category_id: 0,
            province_id: 0,
            city_id: 0,
            district_id: 0,
            street_id: 0,
            address: "",
            longitude: "",
            latitude: "",
            work_week: [],
            work_start_time: "",
            work_end_time: "",
            store_mobile: "",
            staff_name: "",
            business_name: "",
            business_pics: "",
            another_pics: [],
            identity_front_image: "",
            identity_back_image: "",
            owner_name: "",
            owner_mobile: "",
            store_desc: "",
            store_banner: "",
            store_logo: ""
        },
        firstCategoryItem: {},
        secondCategoryItem: {},
        thirdCategoryItem: {},
        CategoryName: "",
        classifyList: [],
        secondLevel: [],
        threeLevel: [],
        addressName: "",
        streetName: "",
        mapdataAddress: "",
        timeState: 1,
        startTimeArr: [],
        endTimeArr: [],
        beginHour: "00",
        beginMinute: "00",
        endHour: "00",
        endMinute: "00",
        businessHours: "",
        timeArrValue: [ 0, 0 ],
        workWeek: [ {
            title: "周一",
            value: "1",
            checked: !1
        }, {
            title: "周二",
            value: "2",
            checked: !1
        }, {
            title: "周三",
            value: "3",
            checked: !1
        }, {
            title: "周四",
            value: "4",
            checked: !1
        }, {
            title: "周五",
            value: "5",
            checked: !1
        }, {
            title: "周六",
            value: "6",
            checked: !1
        }, {
            title: "周日",
            value: "7",
            checked: !1
        } ],
        checkedAll: !1
    },
    onLoad: function(t) {
        var e = this;
        this.categoryList();
        try {
            wx.removeStorageSync("applyaddresspoint");
        } catch (t) {}
        this._getLocation(function(t, a) {
            e.setData({
                "form.longitude": a.lng,
                "form.latitude": a.lat,
                mapdataAddress: t.address
            });
        }), this.storeApply();
    },
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            t && this.setData({
                "form.longitude": t.point.lng,
                "form.latitude": t.point.lat,
                mapdataAddress: t.address
            });
        } catch (t) {
            console.log(t);
        }
    },
    _initData: function() {
        this.setData({
            form: {
                store_name: "",
                first_category_id: 0,
                second_category_id: 0,
                third_category_id: 0,
                province_id: 0,
                city_id: 0,
                district_id: 0,
                street_id: 0,
                address: "",
                longitude: "",
                latitude: "",
                work_week: [],
                work_start_time: "",
                work_end_time: "",
                store_mobile: "",
                staff_name: "",
                business_name: "",
                business_pics: "",
                another_pics: [],
                identity_front_image: "",
                identity_back_image: "",
                owner_name: "",
                owner_mobile: "",
                store_desc: "",
                store_banner: "",
                store_logo: ""
            }
        });
    },
    onStair: function(t) {
        var e = t.currentTarget.dataset.index, a = t.currentTarget.dataset.item, o = [];
        a.has_many_child.length > 0 && (o = a.has_many_child), this.setData({
            classifyIndex: e,
            secondIndex: null,
            threeIndex: null,
            secondLevel: o,
            firstCategoryItem: a,
            secondCategoryItem: {},
            thirdCategoryItem: {},
            threeLevel: []
        });
    },
    onSecond: function(t) {
        var e = t.currentTarget.dataset.index, a = t.currentTarget.dataset.item, o = [];
        a.has_many_child.length > 0 && (o = a.has_many_child), this.setData({
            secondIndex: e,
            threeLevel: o,
            secondCategoryItem: a
        });
    },
    onThreeLevel: function(t) {
        var e = t.currentTarget.dataset.index, a = t.currentTarget.dataset.item;
        this.setData({
            threeIndex: e,
            thirdCategoryItem: a
        });
    },
    onClose: function(t) {
        "hours" === t.currentTarget.dataset.type ? this.setData({
            hoursShow: !1
        }) : this.setData({
            classifyShow: !1
        });
    },
    onAddress: function() {
        this.setData({
            addressShow: !0
        });
    },
    applyPopup: function() {
        this.data.applyTextStatus && this.setData({
            applyShow: !0
        });
    },
    applyClose: function() {
        this.setData({
            applyShow: !1
        });
    },
    getAddress: function(t) {
        var e = t.detail, a = e[0].name + " " + e[1].name + " " + e[2].name;
        this.setData({
            addressName: a,
            "form.province_id": e[0].id,
            "form.city_id": e[1].id,
            "form.district_id": e[2].id,
            addressShow: !1,
            strShow: !0
        }), this.getStreet(e[2].id);
    },
    streetShowbtn: function() {
        this.setData({
            streetShow: !0
        });
    },
    getStreet: function(t) {
        var e = this, o = "";
        o += a.getNetAddresss("member.memberAddress.street"), o += "&district_id=" + t, 
        a._getNetWork({
            url: o,
            success: function(t) {
                var o = t.data;
                1 == o.result && !a._isTextEmpty(o.data) && o.data.length > 0 ? e.setData({
                    districtVal: o.data,
                    strShow: !0
                }) : e.setData({
                    strShow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetConfirm: function(t) {
        var e = t.currentTarget.dataset.item;
        this.setData({
            streetName: e.areaname,
            streetShow: !1,
            "form.street_id": e.id
        });
    },
    onclassifyAffirm: function() {
        if (this.data.firstCategoryItem.id && this.data.secondCategoryItem.id && this.data.thirdCategoryItem.id) {
            var t = "".concat(this.data.firstCategoryItem.name, "/").concat(this.data.secondCategoryItem.name, "/").concat(this.data.thirdCategoryItem.name);
            this.setData({
                "form.first_category_id": this.data.firstCategoryItem.id,
                "form.second_category_id": this.data.secondCategoryItem.id,
                "form.third_category_id": this.data.thirdCategoryItem.id,
                CategoryName: t,
                classifyShow: !1
            });
        } else wx.showToast({
            icon: "none",
            title: "请选择分类",
            duration: 1500
        });
    },
    onAffirm: function(t) {
        var e = this.data.workWeek, a = "".concat(this.data.beginHour, ":").concat(this.data.beginMinute), o = "".concat(this.data.endHour, ":").concat(this.data.endMinute), s = "", i = "", n = [], r = [];
        (n = e.filter(function(t) {
            return !0 === t.checked && t.value;
        })).length > 0 ? Number(this.data.beginHour) < Number(this.data.endHour) ? (n.forEach(function(t) {
            r.push(t.value);
        }), s = n[0].title, i = n[n.length - 1].title, this.setData({
            "form.work_week": r,
            "form.work_start_time": a,
            "form.work_end_time": o,
            businessHours: "".concat(s, "至").concat(i, " ").concat(a, "-").concat(o),
            hoursShow: !1
        })) : wx.showToast({
            icon: "none",
            title: "结束时间不能大于开始时间",
            duration: 1500
        }) : wx.showToast({
            icon: "none",
            title: "请选择店铺营业日期",
            duration: 1500
        });
    },
    toGeolocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation_loc/o2oLocation_loc?tag=storeApply"
        });
    },
    checkChange: function(t) {
        this.setData({
            checkedAll: t.detail
        });
    },
    workWeekOn: function(t) {
        var e = t.currentTarget.dataset.index, a = this.data.workWeek;
        a[e].checked = !a[e].checked, this.setData({
            workWeek: a
        });
    },
    bindChangeTime: function(t) {
        var e = t.detail.value, a = this.data.startTimeArr, o = this.data.endTimeArr;
        1 === this.data.timeState && this.setData({
            beginHour: a[e[0]],
            beginMinute: o[e[1]]
        }), 2 === this.data.timeState && this.setData({
            endHour: a[e[0]],
            endMinute: o[e[1]]
        });
    },
    chooseTimeOn: function(t) {
        var e = t.currentTarget.dataset.state;
        this.setData({
            timeArrValue: [ 0, 0 ]
        }), this.setData({
            timeState: Number(e)
        });
    },
    onPupop: function(t) {
        var e = [], a = [];
        if ("hours" === t.currentTarget.dataset.type) {
            for (var o = 0; o < 24; o++) o < 10 && (o = "0" + o), e.push(o);
            for (var s = 0; s <= 59; s++) s < 10 && (s = "0" + s), a.push(s);
            this.setData({
                hoursShow: !0,
                startTimeArr: e,
                endTimeArr: a
            });
        } else this.setData({
            classifyShow: !0
        });
    },
    modelInput: function(t) {
        var a = t.currentTarget.dataset.item, o = t.detail.value;
        this.setData(e({}, a, o));
    },
    onRefund: function() {
        var t = this;
        if (a._isTextEmpty(this.data.form.store_name)) wx.showToast({
            icon: "none",
            title: "请输入用户名",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.store_logo)) wx.showToast({
            icon: "none",
            title: "请上传商户logo",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.CategoryName)) wx.showToast({
            icon: "none",
            title: "请选择分类",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.addressName)) wx.showToast({
            icon: "none",
            title: "请选择地区",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.streetName)) wx.showToast({
            icon: "none",
            title: "请选择街道",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.address)) wx.showToast({
            icon: "none",
            title: "请输入详细地址",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.longitude) && a._isTextEmpty(this.data.form.latitude)) wx.showToast({
            icon: "none",
            title: "请输入选择定位",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.businessHours)) wx.showToast({
            icon: "none",
            title: "请输入商户营业时间",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.store_mobile)) wx.showToast({
            icon: "none",
            title: "请输入店铺电话",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.staff_name)) wx.showToast({
            icon: "none",
            title: "请输入商户联系人",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.staff_mobile)) wx.showToast({
            icon: "none",
            title: "请输入联系电话",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.business_name)) wx.showToast({
            icon: "none",
            title: "请输入企业名称",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.business_pics)) wx.showToast({
            icon: "none",
            title: "请上传营业执照",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.another_pics)) wx.showToast({
            icon: "none",
            title: "请上传其他补充证件",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.owner_name)) wx.showToast({
            icon: "none",
            title: "请输入运营者姓名",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.owner_mobile)) wx.showToast({
            icon: "none",
            title: "请输入运营者手机号",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.identity_front_image)) wx.showToast({
            icon: "none",
            title: "请上传身份证正面照",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.form.identity_back_image)) wx.showToast({
            icon: "none",
            title: "请上传身份证背面照",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.checkedAll) && this.data.applyTextStatus) wx.showToast({
            icon: "none",
            title: "请同意入驻协议名称",
            duration: 1500
        }); else {
            var e = a.getNetAddresss("plugin.coupon-store.frontend.apply.storeApply");
            a._postNetWork({
                url: e,
                data: this.data.form,
                success: function(e) {
                    var a = e.data;
                    1 == a.result ? (wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }), t._initData(), setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 1e3)) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    categoryList: function() {
        var t = this, e = a.getNetAddresss("plugin.coupon-store.frontend.category.categoryList");
        a._getNetWork({
            url: e,
            success: function(e) {
                var a = e.data;
                1 == a.result ? t.setData({
                    classifyList: a.data.list
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    storeApply: function() {
        var t = this, e = a.getNetAddresss("plugin.coupon-store.frontend.apply.storeApplyPage");
        a._postNetWork({
            url: e,
            data: {
                basic_info: 1
            },
            success: function(e) {
                var a, o, s = e.data;
                1 == s.result ? t.setData({
                    applyText: s.data.apply_text,
                    applyTextStatus: s.data.apply_text_status,
                    applyDescName: null === (a = s.basic_info) || void 0 === a || null === (o = a.plugin_setting) || void 0 === o ? void 0 : o.coupon_store.apply_desc_name
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onRead: function(t) {
        var o = t.currentTarget.dataset.itemname;
        console.log(t);
        var s = this, i = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var a = t.tempFilePaths;
                console.log(a[0]);
                var n = a[0];
                wx.uploadFile({
                    url: i,
                    filePath: n,
                    name: "file",
                    success: function(t) {
                        var a = JSON.parse(t.data);
                        1 == a.result ? s.setData(e({}, o, a.data.img_url)) : wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onanotherPics: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(e) {
                t.unload({
                    tempFilePaths: e.tempFilePaths
                }, "2");
            }
        });
    },
    delIntu_2: function(t) {
        var e = t.currentTarget.dataset.id;
        this.data.anotherImgList.splice(e, 1), this.setData({
            "form.another_pics": this.data.anotherImgList
        });
    },
    unload: function(t, e) {
        console.log(e);
        var o = a.getNetAddresss(this.data.uploadUrl), s = this, i = t.i ? t.i : 0, n = t.success ? t.success : 0, r = t.fail ? t.fail : 0;
        wx.uploadFile({
            url: o,
            filePath: t.tempFilePaths[i],
            name: "file",
            formData: null,
            success: function(t) {
                var a = JSON.parse(t.data);
                console.log(a.data.img_url), ("1" == e || 2 == e) && (s.data.anotherImgList.push(a.data.img_url), 
                s.setData({
                    "form.another_pics": s.data.anotherImgList
                })), console.log(s.data.anotherImgList);
            },
            fail: function(t) {
                r++;
            },
            complete: function(a) {
                ++i == t.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + n + " 失败：" + r)) : (t.i = i, 
                t.success = n, t.fail = r, s.unload(t, e));
            }
        });
    },
    onReady: function() {}
}, e(t, "onShow", function() {}), e(t, "onHide", function() {}), e(t, "onUnload", function() {}), 
e(t, "onPullDownRefresh", function() {}), e(t, "onReachBottom", function() {}), 
e(t, "onShareAppMessage", function() {}), t));